package com.jsftoolkit.gen.builder;

import com.jsftoolkit.base.RequiresResources;
import com.jsftoolkit.base.ResourceInfo;
import com.jsftoolkit.gen.info.RendererInfo;

/**
 * Utility class for filling in a {@link RendererInfo} instance.
 * 
 * @author noah
 * 
 */
public class RendererBuilder extends ChildBuilder<RendererBuilder> {

	private final RendererInfo info;

	/**
	 * 
	 * @param info
	 *            the instance to fill in
	 */
	public RendererBuilder(RendererInfo info) {
		super(info);
		this.info = info;
	}

	/**
	 * Normally this property is filled in by other code.
	 * 
	 * @param decodeParam
	 *            the request parameter to decode
	 * @return this
	 */
	public RendererBuilder decodes(String decodeParam) {
		info.setDecodeParam(decodeParam);
		return this;
	}

	/**
	 * Specifies a template to use. Multiple invocations will add additional
	 * templates all of which will be concatenated together for the renderer.
	 * 
	 * @param template
	 *            the class path location of the template
	 * @return this
	 */
	public RendererBuilder withTemplate(String template) {
		info.addTemplate(template);
		return this;
	}

	/**
	 * 
	 * @param templateEncoding
	 *            the character encoding of the template files.
	 * @return this
	 */
	public RendererBuilder encoded(String templateEncoding) {
		info.setTemplateEncoding(templateEncoding);
		return this;
	}

	/**
	 * Specifies resources for the renderer to include. See
	 * {@link RequiresResources}.
	 * 
	 * @param resources
	 * @return this
	 */
	public RendererBuilder including(ResourceInfo... resources) {
		for (ResourceInfo o : resources) {
			info.addInclude(o);
		}
		return this;
	}

	/**
	 * Specify attributes that are only required by the renderer. Normally this
	 * is filled in by other code.
	 * 
	 * @param attributes
	 * @return this
	 */
	public RendererBuilder withAttributes(String... attributes) {
		for (String attrib : attributes) {
			info.addAttribute(attrib);
		}
		return this;
	}

	public RendererInfo getInfo() {
		return info;
	}

}
